home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / pcvmm.exe / PCVMM.H < prev    next >
C/C++ Source or Header  |  1990-03-14  |  6KB  |  173 lines

  1. /* +----------------------------------------------------------------------+
  2.    |                                                                      |
  3.    |                       p c   V M M Version 1.0                        |
  4.    |                                                                      |
  5.    |                      Created by SUPERIOR SOFT                        |
  6.    |                                                                      |
  7.    |    Copyright (C) 1988,1989,1990 by Superior Soft                     |
  8.    |                                                                      |
  9.    |    All rights reserved. No part of this program source code may      |
  10.    |    be reproduced, stored in a retrieval system, or transmitted,      |
  11.    |    in any form or by any means, electronic, mechanical,              |
  12.    |    photocopying, recording, or otherwise.                            |
  13.    |                                                                      |
  14.    | PCVMM.H                                                              |
  15.    +----------------------------------------------------------------------+
  16. */
  17.  
  18. #define PS_FREE         ((UCHAR)0U)         // page not in use
  19. #define PS_IN_MEM       ((UCHAR)1U)         // in conventional memory
  20. #define PS_DISK         ((UCHAR)2U)         // on disk
  21. #define PS_EMS          ((UCHAR)3U)         // in Expanded memory
  22. #define PS_XMS          ((UCHAR)4U)         // in Extended memory
  23. #define PAGE_SIZE       16384U              // 16K page (plus one paragraph)
  24. #define PAGE_BLOCKS     2000U               // 32M worth of 16k pages
  25. #define VMM_EXT         "VMM"               // swap file extension
  26. #define NULLVMM         ((VHAND)0L)         // used to return error in page functions
  27. #define VH_NULL         ((VHAND)0L)         // used to return error in page functions
  28. #define MEMFREE         ((USHORT)0x0001)    // Bit 0 is used to indicate FREE block
  29. #define _ONE            ((USHORT)0x0001)    // Another Bit 0 mask
  30. #define MEMEND          ((USHORT)0xFFFE)    // Block size value to indicate mem chain end
  31. #define MEMHDRSIZE      ((USHORT)sizeof(USHORT))    // Number of bytes used by mem chunk hdr
  32. #define GETPAGEID(x)    ((x)->pageid)
  33. #define GETPAGEOFF(x)   (((long)((x)->pageid))*PAGE_SIZE)
  34. #define MAXDIRPATH      64
  35. #define SET_MEMPOOL(x)  (memorypool=(UCHAR)(x)) // set the current memory pool
  36.  
  37. #if defined(DEBUG)
  38. #define ERROR(x)        cprintf( "\r\nERROR: " __FILE__ ": %d: " x, __LINE__ ),getch()
  39. #else
  40. #define ERROR(x)
  41. #endif
  42.  
  43. #if !defined(TRUE)
  44. #define TRUE        1
  45. #define FALSE       0
  46. #endif
  47.  
  48. // errors
  49. #define VMM_ERR_NO_PAGE_MEM     1
  50. #define VMM_ERR_NO_SWAP_FILE    2
  51.  
  52. // misc.
  53. typedef unsigned short  USHORT;
  54. typedef unsigned char   UCHAR;
  55.  
  56. // virtual memory handle
  57. typedef unsigned long   VHAND;
  58.  
  59. // virtual memory address component structure
  60. typedef struct VMMID
  61. {
  62.     USHORT          pageoff;
  63.     USHORT          pageid;
  64.  
  65. } VMMID;
  66.  
  67. // virtual memory address structure
  68. typedef union VMADDR
  69. {
  70.     VMMID           vmm;
  71.     VHAND           vh;
  72.  
  73. } VMADDR;
  74.  
  75.  
  76. typedef struct EMM
  77. {
  78.     USHORT          emm_handle,
  79.                     emm_page;
  80.  
  81. } EMM;
  82.  
  83. typedef struct XMS
  84. {
  85.     USHORT          emb_handle;
  86.  
  87. } XMS;
  88.  
  89. typedef struct SEG_OFF
  90. {
  91.     USHORT          off;
  92.     USHORT          seg;
  93.  
  94. } SEG_OFF;
  95.  
  96. typedef union MEMINFO
  97. {
  98.     SEG_OFF     so;
  99.     long        file_offset;
  100.     USHORT  far *wptr;
  101.     UCHAR   far *bptr;
  102.     void    far *mem_addr;
  103.     VMADDR      va;
  104.     XMS         xms;
  105.  
  106. } MEMINFO;
  107.  
  108. typedef struct PAGE
  109. {
  110.     struct PAGE     far *lru_prev;
  111.     struct PAGE     far *lru_next;
  112.  
  113.  
  114.     USHORT          largestchunk;  // largest free chunk in memory page
  115.  
  116.     MEMINFO         meminfo;
  117.  
  118.     USHORT          pageid;
  119.     UCHAR           status;
  120.     UCHAR           mempool;
  121.  
  122. } PAGE;
  123.  
  124. typedef struct LRU_ROOT
  125. {
  126.     struct PAGE far *head,
  127.                 far *tail;
  128.  
  129. } LRU_ROOT;
  130.  
  131. /* external refernced data */
  132. extern UCHAR memorypool;
  133.  
  134.  
  135. /* Function prototypes */
  136. extern  unsigned int pascal open_vmm(char *spath);
  137. extern  void pascal close_vmm(void);
  138. extern  PAGE far * pascal alloc_page(void );
  139. extern  void pascal make_page_head(LRU_ROOT *lru, PAGE far *pg);
  140. extern  void pascal add_lru_head( LRU_ROOT *, PAGE far *);
  141. extern  void pascal add_lru_tail( LRU_ROOT *, PAGE far *);
  142. extern  PAGE far * pascal rem_lru_tail( LRU_ROOT *);
  143. extern  VHAND pascal vmm_alloc(USHORT size);
  144. extern  VHAND pascal vmm_realloc( VHAND vh, USHORT size );
  145. extern  USHORT pascal expand_mem_chunk( PAGE far *pg, USHORT pgoff, USHORT size );
  146. extern  void pascal vmm_free( VHAND vh );
  147. extern  void pascal free_mem_chunk( PAGE far *pg, USHORT pgoff );
  148. extern  void pascal init_mem_page( PAGE far *pg);
  149. extern  void far * pascal vmm_deref( VHAND vmmaddr );
  150. extern  USHORT pascal vmm_size(VHAND vh);
  151. extern  void pascal vmm_dump(void);
  152. extern  USHORT pascal vmm_check(VHAND vh);
  153. extern  void pascal vmm_pack(void);
  154. extern  USHORT pascal alloc_mem_chunk( PAGE far *pg, register USHORT thesize );
  155. extern  void pascal free_page(struct PAGE far *pg);
  156. extern  USHORT pascal read_page(struct PAGE far *pg);
  157. extern  USHORT pascal raw_read_page(struct PAGE far *pg);
  158. extern  USHORT pascal write_page(struct PAGE far *pg);
  159. extern  void far * pascal dmalloc(USHORT size);
  160. extern  void far * pascal drealloc(void far *memptr,USHORT size);
  161. extern  int pascal _dos_seek(int handle,long offset,int origin,long *seekpos);
  162. extern  char * pascal build_swap_path(char *spath);
  163. extern  void pascal dfree(void far *memptr);
  164. extern  void pascal debugmem(void);
  165. extern  void pascal debugstub(void);
  166.  
  167.  
  168.  
  169. /*EOF*/
  170.  
  171.  
  172.  
  173.